package com.ywl.study.transaction.service;

import com.ywl.study.transaction.annotation.GlobalTransaction;
import com.ywl.study.transaction.aspect.DistractDataSourceAspect;
import com.ywl.study.transaction.aspect.DistrictTransactionAspect;
import com.ywl.study.transaction.util.HttpClientUtil;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.client.RestTemplate;


@Service
@Slf4j
public class DemoService {
    @Autowired
    JdbcTemplate jdbcTemplate;

    @Autowired
    DistrictTransactionAspect districtTransactionAspect;

    @Autowired
    DistractDataSourceAspect distractDataSourceAspect;

    @SneakyThrows
    @Transactional
    @GlobalTransaction(isStart = true)
    public void test(){
        log.info("DistrictTransactionAspect="+districtTransactionAspect);
        log.info("DistractDataSourceAspect="+distractDataSourceAspect);

        jdbcTemplate.execute("update account set money=money-100 where id=1");
         HttpClientUtil.getInstance().url("http://localhost:8082");

        jdbcTemplate.execute("update product set num=num-10 where id=1");
        log.info("project-demo中本事务执行完毕。。。。。");
    }



}
